package com.shen.system.util;

import com.shen.system.entity.RoleEntity;
import com.shen.system.entity.UserEntity;
import com.shen.system.info.RoleInfo;
import com.shen.system.info.UserInfo;

import java.util.ArrayList;
import java.util.List;

public class  ConvertUtil {

    /**
     * 转换List
     */
    public static List<UserEntity> userInfosConvertUserEntitys(List<UserInfo> userInfos){
        List<UserEntity> list = new ArrayList<>();

        for (UserInfo u : userInfos){
            list.add(userInfoConvertUserEntity(u));
        }
        return list;
    }

    /**
     * 将UserInfo转成UserEntity
     * @param userInfo
     * @return
     */
    public static UserEntity userInfoConvertUserEntity(UserInfo userInfo){
        UserEntity userEntity = new UserEntity();
        userEntity.setT1(userInfo.getT1());
        userEntity.setUaccount(userInfo.getUaccount());
        userEntity.setDesc(userInfo.getUdesc());
        userEntity.setUid(userInfo.getUid());
        userEntity.setUmail(userInfo.getUmail());
        userEntity.setUname("******");
        userEntity.setUpass(userInfo.getUpass());
        userEntity.setUphone(userInfo.getUphone());
        userEntity.setUtime(userInfo.getUtime());

//        if (null != userInfo.getRoles() ){
////            List<RoleEntity> roles = new ArrayList<>();
////            for (RoleInfo re : userInfo.getRoles()) {
////                roles.add(roleInfoConvertRoleEntity(re));
////            }
//            userEntity.setRoles(roleInfosConvertRoleEntitys(userInfo.getRoles()));
//        }
        return userEntity;
    }


    /**
     * 转UserEntity转换成UserInfo
     */
    public static UserInfo userEntityConvertUserInfo(UserEntity userEntity){
        UserInfo userInfo = new UserInfo();
        userInfo.setT1(userEntity.getT1());
        userInfo.setUaccount(userEntity.getUaccount());
        userInfo.setUdesc(userEntity.getDesc());
        userInfo.setUid(userEntity.getUid());
        userInfo.setUmail(userEntity.getUmail());
        userInfo.setUname(userEntity.getUname());
        userInfo.setUpass(userEntity.getUpass());
        userInfo.setUphone(userEntity.getUphone());
        return userInfo;
    }





    public static List<RoleEntity> roleInfosConvertRoleEntitys(List<RoleInfo> roleInfos){
        List<RoleEntity> list = new ArrayList<>();
        for (RoleInfo roleInfo : roleInfos) {
            list.add(roleInfoConvertRoleEntity(roleInfo));
        }
        return list;

    }

    public static RoleEntity roleInfoConvertRoleEntity(RoleInfo roleInfo){
        RoleEntity roleEntity = new RoleEntity();
        roleEntity.setRid(roleInfo.getRid());
        roleEntity.setRname(roleInfo.getRname());
        roleEntity.setRtype(roleInfo.getRtype());
        roleEntity.setRedesc(roleInfo.getRedesc());

//        if (null != roleInfo.getUsers() && roleInfo.getUsers().size()>0 && roleInfo.getUsers().get(0).getRoles() ==null){
//            roleEntity.setUsers(userInfosConvertUserEntitys(roleInfo.getUsers()));
//        }
        return roleEntity;
    }

    public static RoleInfo roleEntityConvertRoleInfo(RoleEntity roleEntity){
        RoleInfo roleInfo = new RoleInfo();
        roleInfo.setRid(roleEntity.getRid());
        roleInfo.setRedesc(roleEntity.getRedesc());
        roleInfo.setRname(roleEntity.getRname());
        roleInfo.setRtype(roleEntity.getRtype());
        return roleInfo;
    }

}
